import { addNum } from 'shiptools'
import dayjs from 'dayjs'
import { getRefundRecodeApi } from '../../api/index'
import { UPCASE_NUMBERS, TRACER_PAGES, PRODUCT_CODE } from '../../utils/constants'
import { setPage } from '../../utils/index'
const pageName = TRACER_PAGES['refundProgress']
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showRefundProgress: false,
    refundProgressTotalPrice: 0,
    refundRecordRes: [],
    upcaseNumbers: UPCASE_NUMBERS
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.init(options)
    setPage(pageName, PRODUCT_CODE)
  },

  init: function(query) {
    this.getRefundRecode(query)
  },

  
  getRefundRecode: function({serialId}) {
    getRefundRecodeApi({serialId}).then(response => {
      let showRefundProgress = false, refundProgressTotalPrice = 0
      if(response && response.length > 0) {
          showRefundProgress = true
        
          response.map(item => {
              item.RefundDoneTime = dayjs(item.RefundSuccessTime).add(7, 'day').format('YYYY-MM-DD HH:mm');
              refundProgressTotalPrice = addNum(refundProgressTotalPrice, item.RefundAmount)
          })
      }
      this.setData({
        showRefundProgress,
        refundProgressTotalPrice,
        refundRecordRes: response
      })
    })
  },

  phoneCall: function(e) {
    const tel = e.currentTarget.dataset.tel
    if(!tel) return
    wx.makePhoneCall({
      phoneNumber: tel
    })
  }
})